import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/views/login/index.vue'
import Layout from '@/layout/index.vue'

Vue.use(Router)

/*
  redirect:                      if set to 'noredirect', no redirect action will be trigger when clicking the breadcrumb
  meta: {
    title: 'title'               the name showed in subMenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon showed in the sidebar
    breadcrumb: false            if false, the item will be hidden in breadcrumb (default is true)
    hidden: true                 if true, this route will not show in the sidebar (default is false)
  }
*/

export enum ExampleRouterMap {
  Tree = '/tree',
  Table = '/table',
}

export enum RouterMap {
  Login = '/login',
  Root = '/',
  Dashboard = '/dashboard',
  Example = '/example',
  From = '/from',
  Workpace = '/workpace',
  Notfound = '/404',
}

export default new Router({
  // mode: 'history',  // Enable this if you need.
  scrollBehavior: (to, from, savedPosition) => {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  },
  base: process.env.BASE_URL,
  routes: [
    {
      path: RouterMap.Login,
      component: Login,
      meta: {
        title: '登录',
        hidden: true
      }
    },
    {
      path: RouterMap.Root,
      component: Layout,
      redirect: RouterMap.Dashboard,
      children: [
        {
          path: RouterMap.Dashboard,
          component: () => import(/* webpackChunkName: "dashboard" */ '@/views/dashboard/index.vue'),
          meta: {
            title: '大厅',
            icon: 'dashboard'
          }
        }
      ]
    },
    {
      path: RouterMap.Example,
      component: Layout,
      redirect: ExampleRouterMap.Tree,
      meta: {
        title: '组件',
        icon: 'example'
      },
      children: [
        {
          path: ExampleRouterMap.Tree,
          component: () => import(/* webpackChunkName: "tree" */ '@/views/tree/index.vue'),
          meta: {
            title: '树形组件',
            icon: 'tree'
          }
        },
        {
          path: ExampleRouterMap.Table,
          component: () => import(/* webpackChunkName: "table" */ '@/views/table/index.vue'),
          meta: {
            title: '表格组件',
            icon: 'table'
          }
        }
      ]
    },
    {
      path: RouterMap.From,
      component: Layout,
      children: [
        {
          path: 'index',
          component: () => import(/* webpackChunkName: "form" */ '@/views/form/index.vue'),
          meta: {
            title: '表单',
            icon: 'form'
          }
        }
      ]
    },
    {
      path: RouterMap.Workpace,
      component: Layout,
      meta: {
        title: '工作台',
        icon: 'example'
      },
      children: [
        {
          path: 'index',
          component: () => import(/* webpackChunkName: "buildForm" */ '@/views/workpace/index.vue'),
          meta: {
            title: '构建器',
            icon: 'form'
          }
        },
        {
          path: 'button',
          component: () => import(/* webpackChunkName: "button" */ '@/views/workpace/button.vue'),
          meta: {
            title: '按钮组',
            icon: 'nested'
          }
        },
        {
          path: 'fileTree',
          component: () => import(/* webpackChunkName: "button" */ '@/views/workpace/fileTree.vue'),
          meta: {
            title: '文件目录',
            icon: 'nested'
          }
        },
      ]
    },
    {
      path: RouterMap.Notfound,
      component: () => import(/* webpackChunkName: "404" */ '@/views/404.vue'),
      meta: { hidden: true }
    },
    {
      path: '*',
      redirect: RouterMap.Notfound,
      meta: { hidden: true }
    }
  ]
})
